package com.navajo.mvc;

import java.lang.reflect.Field;
import java.util.Observable;
import java.util.Observer;

import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;

public class Controller implements Observer {

	private Model model;
	private View view;

	public Controller() {
		super();
	}

	@Override
	public void update(Observable o, Object arg) {
		System.out.println(o + "  " + arg);

	}

	public Model getModel() {
		return model;
	}

	public void setModel(Model model) {
		this.model = model;
		this.model.addObserver(this);
	}

	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}

	public void wireUp() {

		FieldCallback fieldCallback = new FieldCallback() {

			@Override
			public void doWith(Field field) throws IllegalArgumentException,
					IllegalAccessException {

				System.out.println(field);

			}
		};

		ReflectionUtils.doWithFields(this.getView().getClass(), fieldCallback);
	}
}
